home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13964 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.0 KB  |  114 lines

  1. Path: news.cloudnet.com!news
  2. From: "Randall J. Pfeifer" <rpfeifer@cloudnet.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Nee help with a string and temp string
  5. Date: Wed, 10 Apr 1996 21:47:40 -0500
  6. Organization: Cloudnet, St. Cloud, MN
  7. Message-ID: <316C72CC.763A@cloudnet.com>
  8. NNTP-Posting-Host: pm184.cloudnet.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.01 (Win95; I)
  13.  
  14. I am writing a program that reads data, validates it, and then writes it to a new file.
  15.  
  16. My problem involves evaluating the second line. The program works like this.
  17.  
  18. An 80 byte line is read from an ascii file. There can be many lines of data.
  19. Once a line is read, various components are evaulated.
  20.   ie  column 1 must always contain a "B".
  21.       column 5-9 will contain a number padded with zeros from the left if necessary.
  22.       ect.
  23.  
  24. As each component is evaluated the result is concatenad to a buffer string, with the
  25. first component that is evaulated being copied instead of concatenaded.
  26. Once the whole line is evaulated and corrected if necessary, I write that line to a file.
  27.  
  28. I then read another line and start the process over again.
  29.  
  30. My problem involves lines 2 through X.
  31.   Reading the data is fine. However, when I evaluate the components and write them to the
  32.   buffer the previous lines data still resides in the string.
  33.  
  34. How can I get rid of the old lines data in my temp string.
  35.  
  36. I apologize for the length, but I have included a section of the code to help you understand
  37.  my problem.
  38.  
  39. Bcard is the temp string.
  40. line is the string that contains the line of data read from a file
  41. padright is a routine that pads numbers with zero.
  42.  
  43. With one line of data this section works just fine. It only bombs on multile line of data
  44.  
  45.  
  46. I thank you in advance for any possible help.
  47.  
  48. Randall Pfeifer
  49.  
  50. void main();
  51. void examineAcard();
  52. void examineBcard();
  53. void examineCcard();
  54. void padright(char card[81], int start, int end, int size, int base);
  55. void readcard(char *card);
  56. void writecard();
  57. char Acard[81], Bcard[81], Ccard[81];
  58.  
  59. int Counter = 0;
  60. char line[80];
  61.  
  62. char *Space = "   ";
  63.  
  64. FILE *fpcardrd, *fpcardwrt;
  65.  
  66. void main()
  67. { int count;
  68.  
  69.   readcard("BCARD");
  70.   writecard();
  71.  
  72.   while ( fgets(line,80,fpcardrd) != NULL)
  73.    {
  74.     examineBcard();
  75.    }
  76.   fclose(fpcardwrt);
  77. }
  78.  
  79. void examineBcard()
  80. { int result;
  81.   
  82.   strncpy(Bcard,"B",1);
  83.   strncat(Bcard,&line[1],1);
  84.   strncat(Bcard, Space,3);
  85.  
  86.   padright(Bcard,5,7,3,3);
  87.   padright(Bcard,8,12,5,5);
  88.   padright(Bcard,13,18,6,6);
  89.   strncat(Bcard," ",1);
  90.  
  91.   padright(Bcard,20,22,3,3);
  92.   padright(Bcard,23,27,5,5);
  93.   padright(Bcard,28,33,6,6);
  94.   strncat(Bcard," ",1);
  95.  
  96.   padright(Bcard,35,37,3,3);
  97.   padright(Bcard,38,43,5,5);
  98.   padright(Bcard,43,48,6,6);
  99.   strncat(Bcard," ",1);
  100.  
  101.   padright(Bcard,50,52,3,3);
  102.   padright(Bcard,53,57,5,5);
  103.   padright(Bcard,58,63,6,6);
  104.   strncat(Bcard," ",1);
  105.  
  106.   padright(Bcard,65,67,3,3);
  107.   padright(Bcard,68,72,5,5);
  108.   padright(Bcard,73,78,6,6);
  109.   strncat(Bcard,"\n",1);
  110.   
  111.   fputs(Bcard,fpcardwrt);
  112.  
  113.  }
  114.